package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.ClientBean;
import com.project.mapper.IClientMapper;
import com.project.service.IClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;

@Service
@Transactional
public class ClientServiceImpl implements IClientService {

    @Autowired
    private IClientMapper mapper;//报错显示，没有写mapper注解

    @Override
    public PageInfo<ClientBean> findByItem(int page, int pageSize, String clientName, String clientRange) {
        PageHelper.startPage(page,pageSize);
        PageInfo<ClientBean>pageInfo=PageInfo.of(mapper.findByItem(clientName, clientRange));
        return pageInfo;
    }

    @Override
    public boolean addClient(ClientBean client) {
        ClientBean clientBean= mapper.selectOne(new QueryWrapper<ClientBean>().eq("clientName",client.getClientName()));
        if(clientBean != null){
            return false;
        }
        mapper.addClient(client);
        return true;
    }

    @Override
    public ClientBean findById(int id) {
        return mapper.findById(id);
    }

    @Override
    public void updateClient(ClientBean client) {
//        mapper.updateClient(client);
    }

    @Override
    public List<ClientBean> findAll() {
        return mapper.findAll();
    }

    @Override
    public PageInfo<ClientBean> findMoneyItem(int page, int pageSize, String client, LocalDate startDate, LocalDate endDate) {
        PageHelper.startPage(page,pageSize);
        PageInfo<ClientBean>pageInfo=PageInfo.of(mapper.findMoneyByItem(client, startDate, endDate));
        return pageInfo;
    }
}
